import 'package:flutter/material.dart';
import 'package:flutter_rider/generated/assets.dart';
import 'package:flutter_rider/main/widgets/ext/u_layout.dart';
import 'package:flutter_rider/main/widgets/ext/u_text.dart';
import 'package:flutter_rider/utils/log.dart';
import 'package:flutter_rider/utils/screen_fit.dart';
import 'package:flutter_svg/flutter_svg.dart';
import '../../../main/widgets/ui_constant.dart';

class UTitleLayout {
  static PreferredSizeWidget getBackTitle2(BuildContext context, String title) {
    return PreferredSize(
      preferredSize: Size(0, 44.rpx),
      child: AppBar(
        elevation: 1.rpx,
        titleSpacing: 0,
        backgroundColor: UIColor.color_content,
        leading: IconButton(
          iconSize: 18.rpx,
          icon: const Icon(
            Icons.arrow_back_ios_new,
            color: UIColor.color_t1,
          ),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
        centerTitle: true,
        title: UText.get(title, UIColor.color_t1, 17.rpx),
      ),
    );
  }

  static PreferredSizeWidget getBackTitle(BuildContext context, String title) {
    return PreferredSize(
      preferredSize: Size(0, 44.rpx),
      child: Container(
        decoration:
            const BoxDecoration(color: UIColor.color_content, boxShadow: [
          BoxShadow(color: Colors.black12, offset: Offset(1, 1), blurRadius: 1),
        ]),
        padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
        width: double.infinity,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            SizedBox(
              width: 50.rpx,
              child: IconButton(
                iconSize: 18.rpx,
                icon: const Icon(
                  Icons.arrow_back_ios_new,
                  color: UIColor.color_t1,
                ),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            ),
            Expanded(
              child: Center(
                child: UText.get(title, UIColor.color_t1, 17.rpx,
                    fw: FontWeight.w600),
              ),
            ),
            50.wspace,
          ],
        ),
      ),
    );
  }

  static PreferredSizeWidget getBackTitleRight(BuildContext context,
      String title, String rightTitle, Function()? rightTitleOnTap) {
    return PreferredSize(
      preferredSize: Size(0, 44.rpx),
      child: Container(
          decoration:
              const BoxDecoration(color: UIColor.color_content, boxShadow: [
            BoxShadow(
                color: Colors.black12, offset: Offset(1, 1), blurRadius: 1),
          ]),
          padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
          width: double.infinity,
          child: Stack(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  SizedBox(
                    width: 50.rpx,
                    child: IconButton(
                      iconSize: 18.rpx,
                      icon: const Icon(
                        Icons.arrow_back_ios_new,
                        color: UIColor.color_t1,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                    ),
                  ),
                  Expanded(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        UText.get(title, UIColor.color_t1, 17.rpx,
                            fw: FontWeight.w600),
                      ],
                    ),
                  ),
                  50.wspace,
                ],
              ),
              Positioned(
                  right: 16.rpx,
                  bottom: 10.rpx,
                  child: GestureDetector(
                    onTap: rightTitleOnTap,
                    child: Text(
                      rightTitle,
                      style: TextStyle(
                        fontSize: 16.rpx,
                        color: UIColor.color_primary,
                        decorationColor: UIColor.color_primary,
                      ),
                    ),
                  ))
            ],
          )),
    );
  }

  static PreferredSizeWidget getMessageBackTitle(
      BuildContext context, String title) {
    return PreferredSize(
      preferredSize: Size(0, 44.rpx),
      child: Container(
        decoration:
            const BoxDecoration(color: UIColor.color_content, boxShadow: [
          BoxShadow(color: Colors.black12, offset: Offset(1, 1), blurRadius: 1),
        ]),
        padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
        width: double.infinity,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            SizedBox(
              width: 50.rpx,
              child: IconButton(
                iconSize: 18.rpx,
                icon: const Icon(
                  Icons.arrow_back_ios_new,
                  color: UIColor.color_t1,
                ),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            ),
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  UText.get(title, UIColor.color_t1, 17.rpx,
                      fw: FontWeight.w600),
                  Container(
                    // iconSize: 24.rpx,
                    padding: EdgeInsets.only(left: 4.rpx),
                    child: SvgPicture.asset(Assets.imageMineBroom,
                        width: 24.rpx, height: 24.rpx),
                  ).onTap(() {
                    Log.i("点击了清理消息");
                    // NavigatorUtils.push(context, MineRouter.messagePage);
                  })
                ],
              ),
            ),
            50.wspace,
          ],
        ),
      ),
    );
  }
}
